/**
 * 数据分析service
 */
(function(window, angular, undefined) {
	/**
	 * 报表service
	 */
	var DataAnalysisServiceModule = angular.module(
			'DataAnalysisServiceModule', [ 'ui.router', 'itfreer',
					'waterCommon' ]);

	DataAnalysisServiceModule.service('$DataAnalysisService', function($itfreerHttp, $itfreer, $waterDataCommon,$rootScope, $httpData, $state,$queryObj) {
		var me = this;
		
		me.showChar = function(reportData,domid,parmsToChar,charType,needPre){
			var parmMap = {};
			var parmToCheckList = parmsToChar;
			for(var i in parmToCheckList){
				var obj = parmToCheckList[i];
				parmMap[obj.name] = obj.avgText;
			}
			
			$("#"+domid).empty();
			var data = reportData[0].report;
			var datetimes = reportData[0].yearHeadText;
			//获取全部历史数据用于图表展示
			
			if(data && data.length){
				
				for(var rowIndex=0;rowIndex<data.length;rowIndex++){
					var parm = [data[rowIndex].PARMNAME];
					var charData = [];
					if(data.length == 1){
						var charDiv = $("<div class='charDiv' id='"+domid+parm+"'></div>").css({height: 300,width:($rootScope.Map_W - $rootScope.widthOff)});
						$("#"+domid).append(charDiv);
					}
					else{
						var charDiv = $("<div class='charDiv' id='"+domid+parm+"'></div>").css({height: 300,width:($rootScope.Map_W - $rootScope.widthOff+200)/2});
						$("#"+domid).append(charDiv);
					}
					
					for(var i=0;i<datetimes.length;i++){
						var datetime = datetimes[i];
						var value = data[rowIndex]["P"+datetime];
						if(!value){
							value = undefined;
						}
						
						if(value && needPre){
							var max = data[rowIndex].ABNORMAL_MAX;
							var min = data[rowIndex].ABNORMAL_MIN;
							if(max && min){
								value = value / (max - min);
							}
						}
						
						charData.push(value);
					}
					
					$waterDataCommon.showMulitLineChar(parm,datetimes,[charData],domid+parm[0],charType);
				}
			}
		}
		var trendChart="";
		/**
		 * 绘制趋势图
		 * 
		 */
		me.DrawTrendChart = function(data,domid) {
			var charData =[];
			charData = data;
			var chartContainer = document.getElementById(domid);
			 trendChart = echarts.init(chartContainer);
			

			//取时间刻度，如：2016年05月     
			var datetimes = charData.dateText;
			//取数据部分
			var data = charData.stationItem;
			if(data.length==1){
				var title = data[0].stationName+'  '+data[0].pollName+'趋势图 ';
				var value = data[0].data;
				if(value!=null) {
					var meanValue=[];
					var maxValue=[];
					var minValue=[];
					for(var j =0;j<datetimes.length; j++) {
						var mmm = value['P'+datetimes[j]];
						//取均值，默认第1个值
						meanValue.push(mmm[0]);
						var total=[];
						total.push(maxValue);
					}
				}
				var maminavg=[];
				var avgValue=[];
				for(var i = 0;i<meanValue.length;i++) {
					maminavg[i]=meanValue[i];
				}
				//升序排序
				meanValue.sort(function(n1,n2){
				 	return n1-n2;
				 });
/*				console.log(meanValue,maminavg);*/
				var total=0;
				for(var i=0;i<maminavg.length;i++) {
					total+= maminavg[i];
				}
				var avg = 0;
				avg = (parseFloat(meanValue[0])+parseFloat(meanValue[meanValue.length-1]))/2;
				//存放排序后的第一个作为最小值，均值作为第二个只，升序排列后的最后一个值为最大值。，画一条直线。
				var min = meanValue[0];
				var max = meanValue[meanValue.length-1];
				var agg = (max-min)/datetimes.length;
				avgValue.push(meanValue[0]);
				for(var i=1;i<datetimes.length-1;i++) {
					avgValue.push(parseFloat(meanValue[0])+parseFloat(agg)*i);
				}
				avgValue.push(meanValue[meanValue.length-1]);
				trendChart.setOption({
				    title : {
				        text: title,
				        textStyle: {
				            fontSize: 12,
				            fontWeight: 'bolder',
				            color: '#333'          // 主标题文字颜色
				        }
				    },
				    tooltip : {
				        trigger: 'axis'
				    },
				    legend: {
				        data:['均值']
				    },
				    toolbox: {
				        show : true,
				        feature : {
				            mark : {show: true},
				            dataView : {show: true, readOnly: false},
				            magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
				            restore : {show: true},
				            saveAsImage : {show: true}
				        }
				    },
				    calculable : true,
				    xAxis : [
				        {
				            type : 'category',
				            boundaryGap : false,
				            data : datetimes
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value',
				            axisLabel : {
				                formatter: '{value}'+' '+data[0].parmUnit
				            }
				        }
				    ],
				    series : [
				        {
				        	show:false,
				            name:'均值',
				            type:'line',
				            smooth:true,
				            data:maminavg,
				            markPoint : {
				                data : [
				                    {type : 'max', name: '最大值'},
				                    {type : 'min', name: '最小值'}
				                ]
				            }
				        },	
				        {
				        	show:true,
				            type:'line',
				            smooth:true,
				            data:avgValue
				        }
				    ]
				});
			}
		}
		
		/**
		 * 
		 * 绘制多个站点的曲线图
		 */
		me.drawMultiTrendChart = function(data,domid) {
			var charData =[];
			charData = data;
			var chartContainer = document.getElementById(domid);
			 trendChart = echarts.init(chartContainer);
			

			//取时间刻度，如：2016年05月     
			var datetimes = charData.dateText;
			//取数据部分
			var data = charData.stationItem;
			if(data.length>1){
				
				var title = data[0].pollName+'均值趋势图 ';
				var total=[];
				var dataTitle=[];
				var dataTitle1=[];
				for(var i = 0;i < data.length; i++) {
					var meanValue=[];
					var value = data[i].data;
					if(value!=null) {
						
						for(var j =0;j<datetimes.length; j++) {
							var mmm=[];
							mmm = value['P'+datetimes[j]];
							//取均值，默认第1个值
							meanValue.push(mmm[0]);							
							
						}
						total.push(meanValue);
					}
					dataTitle.push(data[i].stationName+data[i].pollName);
					dataTitle1.push(data[i].stationName);
				}
				var dd=[];
				
				for (var k = 0; k< total.length; k++) {
					var aa={};
					aa={
							name:dataTitle1[k],
				            type:'line',
				            smooth:true,
				            data:total[k] 
				        }
					dd.push(aa);			
				}

				var option= {
				    title : {
				        text: title,
				        textStyle: {
				            fontSize: 12,
				            fontWeight: 'bolder',
				            color: '#333'          // 主标题文字颜色
				        }
				    },
				    tooltip : {
				        trigger: 'axis'
				    },
				    legend: {
				        data:dataTitle1
				    },
				    toolbox: {
				        show : true,
				        feature : {
				            mark : {show: true},
				            dataView : {show: true, readOnly: false},
				            magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']},
				            restore : {show: true},
				            saveAsImage : {show: true}
				        }
				    },
				    calculable : true,
				    xAxis : [
				        {
				            type : 'category',
				            data : datetimes
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value',
				            axisLabel : {
				                formatter: '{value}'+' '+data[0].parmUnit
				            }
				        }
				    ],
				    series : dd
				};
				trendChart.setOption(option);
			}
		}
		
		/**
		 * 	绘制趋势分析中的柱形图，用于污染物水质数据对比分析
		 * 
		 */
		me.drawHistogramChart1 = function(data,domid) {
			var charData =[];
			var chartContainer = document.getElementById(domid);
			 trendChart = echarts.init(chartContainer);
			 //如果传入数据为空，直接清空图像；
				if(data==null) {
					trendChart.setOption("");
					return;
				}
			charData = data;
			//取时间刻度，如：2016年05月     
			var datetimes = charData.dateText;
			//取数据部分
			var data = charData.stationItem;
			if(data.length>1){
				
				var title = data[0].name+'水质数据比对 ';
				var total=[];
				var dataTitle=[];
				var dataTitle1=[];
				for(var i = 0;i < data.length; i++) {
					var meanValue=[];
					var value = data[i].data;
					if(value!=null) {
						
						for(var j =0;j<datetimes.length; j++) {
							var mmm=[];
							mmm = value['P'+datetimes[j]];
							//取均值，默认第1个值
							meanValue.push(mmm[0]);							
							
						}
						total.push(meanValue);
					}
					dataTitle.push(data[i].stationName+data[i].pollName);
					dataTitle1.push(data[i].stationName);
				}
				var dd=[];
				
				for (var k = 0; k< total.length; k++) {
					var aa={};
					aa={
							name:dataTitle1[k],
				            type:'bar',
				            smooth:true,
				            data:total[k] 
				        }
					dd.push(aa);			
				}

				var option= {
				    title : {
				        text: title,
				        textStyle: {
				            fontSize: 12,
				            fontWeight: 'bolder',
				            color: '#333'          // 主标题文字颜色
				        }
				    },
				    tooltip : {
				        trigger: 'axis'
				    },
				    legend: {
				        data:dataTitle1,
				        x: 'right',
				        y: 'top'
				    },
				    calculable : true,
				    xAxis : [
				        {
				            type : 'category',
				            boundaryGap : true,
				            data : datetimes
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value',
				            axisLabel : {
				                formatter: '{value}'+' '+data[0].parmUnit
				            }
				        }
				    ],
				    series : dd
				};
				trendChart.setOption(option);
			}
		}
		
		/**
		 * 		绘制趋势分析中的下面一个柱形图，用于污染物水质数据对比分析
		 * 
		 */		
		me.drawHistogramChart2 = function(data,domid) {
			var charData =[];
			var chartContainer = document.getElementById(domid);
			 trendChart = echarts.init(chartContainer);
			 //如果传入数据为空，直接清空图像；
				if(data==null) {
					trendChart.setOption("");
					return;
				}
				charData = data;
			//取时间刻度，如：2016年05月
			var datetimes = charData.dateText;
			//取数据部分
			var data = charData.stationItem;
			var dd=[];
			if(data.length>1){
				
				var title = data[0].name+'水质数据比对 ';
				var total=[];
				var dataTitle=[];
				var dataTitle1=[];
				//循环得到查询多少个日期，比如8月1日到8月10日，是个日期
				for(var k=0;k<datetimes.length;k++) {
					var meanValue=[];
					for(var j=0;j<data.length;j++) {
						var ss=[];
						ss= data[j].data['P'+datetimes[k]];
						meanValue.push(ss[0]);
					}
					var aa={};
					aa={
							name:datetimes[k],
				            type:'bar',
				            smooth:true,
				            data:meanValue 
				        }
					dd.push(aa);	
				}
				for(var i = 0;i < data.length; i++) {
					dataTitle1.push(data[i].stationName);
				}

				var option= {
				    title : {
				        text: title,
				        textStyle: {
				            fontSize: 12,
				            fontWeight: 'bolder',
				            color: '#333'          // 主标题文字颜色
				        },
				        x: 'left',                 // 水平安放位置，默认为左对齐，可选为：
				        y: 'top'
				    },
				    tooltip : {
				        trigger: 'axis'
				    },
				    legend: {
				        data:datetimes,
				        x: 'right',
				        y: 'top'
				    },
				    calculable : true,
				    xAxis : [
				        {
				            type : 'category',
				            boundaryGap : true,
				            data : dataTitle1 
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value',
				            axisLabel : {
				                formatter: '{value}'+' '+data[0].parmUnit
				            }
				        }
				    ],
				    series : dd
				};
				trendChart.setOption(option);
			}
		}
		/**
		 * 绘制对比分析饼图
		 */
		me.DrawCompareChart = function(data,domid) {
			var charData =[];
			charData = data;
			var chartContainer = document.getElementById(domid);
			var myChart = echarts.init(chartContainer);
			
			var data = charData[0].report;
			//取时间刻度，如：2016年五月     
			//在data.report中存放均值的参数为 PARMNAME:78.23
			var datetimes = charData[0].yearHeadText;
			if(data){
				
				var parms = [];
				var charDatas = [];
				for(var rowIndex=0; rowIndex < data.length;rowIndex++) {
					//遍历取各个污染物名称
					parms.push(data[rowIndex].PARMNAME);
					
					
					//取对应时间的均值：P2015年10月 :25.23
					var meanValue = data[rowIndex]["AVG"];
				
					if(!meanValue) {
						meanValue = "";
					}
					charDatas.push(meanValue);
					
					myChart.setOption({
						    title : {
						        text: '污染物同比，环比柱状图',
						        textStyle: {
						            fontSize: 12,
						            fontWeight: 'bolder',
						            color: '#333'          // 主标题文字颜色
						        }
						    },
						    tooltip : {
						        trigger: 'axis'
						    },
						    legend: {
						        data:['均值']
						    },
						    toolbox: {
						        show : true,
						        feature : {
						            mark : {show: true},
						            dataView : {show: true, readOnly: false},
						            magicType : {show: true, type: [ 'bar','line']},
						            restore : {show: true},
						            saveAsImage : {show: true}
						        }
						    },
						    calculable : true,
						    xAxis : [
						        {
						            type : 'category',
						            boundaryGap : false,
						            data : datetimes
						        }
						    ],
						    yAxis : [
						        {
						            type : 'value',
						            axisLabel : {
						                formatter: '{value}'+' '+data[0].parmUnit
						            }
						        }
						    ],
						    series : [
					              {
						            name:'均值',
						            type:'bar',
						            smooth:true,
						            itemStyle: {normal: {areaStyle: {type: 'default'}}},
						            data:charDatas
						          }
						       ]
						});
					
				}
			}
		}
		
		me.DrawMulitCouBar = function(data,domId,poll){
			$("#"+domId).empty();
			var chartContainer = document.getElementById(domId);
			var myChart = echarts.init(chartContainer);
			var legend = [];
			for(var p=0;p<data.conData.stations.length;p++){
				legend.push(data.conData.stations[p].NAME);
			}
			legend.push("其他");
			
			var options = [
				        {
				            title : {
				                text: '',
				                subtext: ''
				            },
				            tooltip : {
				                trigger: 'item',
				                formatter: "{a} <br/>{b} : {c} ({d}%)"
				            },
				            legend: {
				                data:legend
				            },
				            toolbox: {
				                show : true,
				                feature : {
				                    mark : {show: true},
				                    dataView : {show: true, readOnly: false},
				                    magicType : {
				                        show: true, 
				                        type: ['pie', 'funnel'],
				                        option: {
				                            funnel: {
				                                x: '25%',
				                                width: '50%',
				                                funnelAlign: 'left',
				                                max: 1700
				                            }
				                        }
				                    },
				                    restore : {show: true},
				                    saveAsImage : {show: true}
				                }
				            }
				        }
				     ];
			
			for(var q=0;q<data.conData.dateTexts.length;q++){
				var seriesData=[];
				var totalCou = 0;
				var curDateText = data.conData.dateTexts[q];
				for(var i =0;i<data.snData.data.length;i++){
					var cou = parseFloat(data.snData.data[i]["COU"+curDateText]);
					if(!isNaN(cou)){
						totalCou = totalCou+cou;
					}
				}
				
				var conTotal = 0;
				for(var j=0;j<data.conData.data.length;j++){
					var conRow = data.conData.data[j];
					var pollName = conRow.PARMNAME;
					var stationName = conRow.STATION_NAME;
					if(pollName != poll){
						continue;
					}
					var concou = parseFloat(conRow["COU"+curDateText]);
					
					if(!isNaN(concou)){
						conTotal = conTotal+concou;
						seriesData.push({value:concou,name:stationName});
					}
					else{
						seriesData.push({value:0,name:stationName});
					}
				}
				
				var restCou = totalCou - conTotal;
				if(restCou <= 0){
					restCou = 0;
					seriesData.push({value:0,name:"其他"});
				}
				else{
					seriesData.push({value:restCou,name:"其他"});
				}
				options.push({series:[{
	                    type:'pie',
	                    data:seriesData,
	                    name:"",
	                    center: ['50%', '45%'],
	                    radius: '50%'
				}]});
			}
			if(options.length>1) {
				options[0].series = options[1].series;
			}
			var option = {
				    timeline : {
				    	axisType:'category',
				        data : data.conData.dateTexts,
				        label : {
				            formatter : function(s,a,b,c,d,e,f,g) {
				                return s;
				            }
				        }
				    },
				    options:options
			};
			myChart.setOption(option);
		}
		
		/**
		 * 地表水通量分析
		 * 
		 */
		me.DrawBingTuPollCouChart=function(data,domId){	
			$("#"+domId).empty();
			var legendNames=[];	
			var chartContainer = document.getElementById(domId);
			var myChart = echarts.init(chartContainer);
			var valueList=[];	
			for(var i=0;i<data.pollNameList.length;i++){							 								
				var valuename={};
				var parnmae="A"+data.pollNameList[i].S_DOMAINCODE;		
				valuename={};
				
				if(data.SumData[0][parnmae]==null){
					valuename.value=0;
					valuename.name=data.pollNameList[i].S_DOMAINCAPTION+"(0)";
				}else{
					valuename.value=data.conStationList[0][parnmae];	
					valuename.name=data.pollNameList[i].S_DOMAINCAPTION+"("+data.SumData[0][parnmae].toFixed(2)+")";
				}
				
				valueList.push(valuename);
			}
					myChart.setOption({
							    title : {
							        text:'通量分析饼图',
							        x:'center'
							    },
							    tooltip : {
							        trigger: 'item',
							        formatter: "{a} <br/>{b} : {c} ({d}%)"
							    },
							    legend: {
							        orient: 'vertical',
							        x: 'left',
							        data: valueList
							    },
							    series : [
							        {
							            name: '通量分析',
							            type: 'pie',
							            radius : '55%',
							            center: ['50%', '60%'],
							            data: valueList ,
							            itemStyle: {
							                emphasis: {
							                    shadowBlur: 10,
							                    shadowOffsetX: 0,
							                    shadowColor: 'rgba(0, 0, 0, 0.5)'
							                }
							            }
							        }
							    ]
							});
				
		}
		/**
		 * 绘制水质类别分析饼图
		 * 
		 */
		me.DrawBingTuWaterTypeChart = function(typedata,domid) {
			var charData =[];
			charData = typedata.stationWaterType;
			var Units = typedata.labelName;
			var stationName = [];
			var chartContainer = document.getElementById(domid);
			var myChart = echarts.init(chartContainer);
			var timeLength = typedata.timeLength;
			//取所有站点名称
			stationName = typedata.stationName;
			var Name=[];
			for(var i = 0;i<stationName.length;i++) {
				var name={};
				name=stationName[i].NAME;
				Name.push(name);
			}
			//取几类对应的值。
			
			var one =0;
			var two =0;
			var three =0;
			var four =0;
			var five =0;
			var six =0;
			var stationData = [];
			var typeData =[];
			if(charData) {
				for(var i=0;i<charData.length;i++) {
					var typeS = charData[i].STATIONTYPE;
					var staName = charData[i].STATIONNAME;
					if(typeS=="I"){
						one=one+1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeOne={};
							TypeOne.value=1;
							TypeOne.name=staName;
							TypeOne.type = typeS;
							stationData.push(TypeOne);
						}
					} else if (typeS=="II"){
						two += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeTwo={};
							TypeTwo.value=1;
							TypeTwo.name=staName;
							TypeTwo.type = typeS;
							stationData.push(TypeTwo);
						}

					} else if (typeS=="III"){
						three += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && stationData[k].type==typeS) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {							
							var TypeThree={};
							TypeThree.value=1;
							TypeThree.name=staName;
							TypeThree.type=typeS;
							stationData.push(TypeThree);
						}
					 } else if (typeS=="IV"){
						four += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name&& typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeFour={};
							TypeFour.value=1;
							TypeFour.name=staName;
							TypeFour.type=typeS;
							stationData.push(TypeFour);
						}
					 } else if (typeS=="V"){
						five += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name&& typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeFive={};
							TypeFive.value=1;
							TypeFive.name=staName;
							TypeFive.type=typeS;
							stationData.push(TypeFive);
						}
					 } else if (typeS=="劣V"){
						six += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name&& typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeSix={};
							TypeSix.value=1;
							TypeSix.name=staName;
							TypeSix.type=typeS;
							stationData.push(TypeSix);
						}
					 }
				}
				var colors=[];
				if(one>0) {
					var data={};
					data.value=one;
					data.name="I类";
					typeData.push(data);
					colors.push("blue");
				}
				if(two>0) {
					var data={};
					data.value=two;
					data.name="II类";
					typeData.push(data);
					colors.push("blue");
				}
				if(three>0) {
					var data={};
					data.value=three;
					data.name="III类";
					typeData.push(data);
					colors.push("green");
				}
				if(four>0) {
					var data={};
					data.value=four;
					data.name="IV类";
					typeData.push(data);
					colors.push("yellow");
				}
				if(five>0) {
					var data={};
					data.value=five;
					data.name="V类";
					typeData.push(data);
					colors.push("orange");
				}
				if(six>0) {
					var data={};
					data.value=six;
					data.name="劣V类";
					typeData.push(data);
					colors.push("red");
				}
				stationData.sort(me.compare("type"));
				//去掉type属性
				var result=[];
				for(var i = 0;i<stationData.length;i++) {
					var array={};
					for(var a in stationData[i])
				    {  
				        if(a!="type")
				        {
				        	array[a]=stationData[i][a];
				         }
				    }
					result[i]=array;
				}
				var format = '';
				if(Units=='（天）') {
					format = '{b} \n {c} （天） ({d}%)';
				} else if(Units=='（周）') {
					format = '{b} \n {c} （周） ({d}%)';
				}else if(Units=='（月）') {
					format = '{b} \n {c} （月） ({d}%)';
				}else if(Units=='（季度）') {
					format = '{b} \n {c} （季度） ({d}%)';
				}else if(Units=='（年）') {
					format = '{b} \n {c} （年） ({d}%)';
				}
				stationData = result;
				var titles='站点水质类别';
				if(stationData.length==0) {
					titles='';
				}
				 var option = {
						    title : {//图形名称
						        text: titles,
						        x:'center',
						        textStyle: {
						            fontSize: 12,
						            fontWeight: 'bolder',
						            color: ['black']          // 主标题文字颜色
						        }
						    },
						       tooltip: { 
									trigger: 'item', 
									formatter: "{a} <br/>{b}: {c} ({d}%)" 
								}, 
							legend: { 
						        orient : 'horizontal',
						        x : 'left',
						        y:'50px',
								data:Name
							}, 
				            color:colors,
					    series : [
							        {
							            name:'综合水质类别',
							            type:'pie',
							            selectedMode: 'single', //单一选中模式 
										radius: [0, '30%'], //饼图的半径 [内半径，外半径] 
								        textStyle: {
								            fontSize: 6,
								            fontWeight: 'bolder',
								            color: ['black']          // 主标题文字颜色
								        },
											itemStyle : {
												normal : {
													label : {
														position : 'inner',
													    textStyle:{
														    color:'rgba(0,0,0,0.8)'
														}
													},
													labelLine : {
														show : false
													}
												}
										},
							            data:typeData
							        },
							        {
										name:'水质类别', 
										type:'pie', 
										radius: ['40%', '50%'], 
								        textStyle: {
								            fontSize: 6,
								            fontWeight: 'bolder',
								            color: '#666'          // 主标题文字颜色
								        },
										data:stationData,
											itemStyle:{ 
												normal:{ 
													  label:{ 
														show: true, 
														formatter: format ,
													    textStyle:{
														    color:'rgba(0,0,0,0.8)'
														}
													  }, 
													  labelLine :{show:true} 
													} 
										}
									}
					        ]
					};
				 myChart.setOption(option);
			} else {
				 myChart.setOption("");
			}
		}
		/**
		 * 绘制综合污染指数水质状况饼图
		 * 
		 */
		me.DrawBingTuCompPollIndexChart = function(typedata,domid) {
			var charData =[];
			var Units = typedata.labelName;
			charData = typedata.compPollIndex;
			var timeLength = typedata.timeLength;
			
			var stationName = typedata.stationName;
			var chartContainer = document.getElementById(domid);
			var myChart = echarts.init(chartContainer);
			var Names=[];
			for(var i = 0;i<stationName.length;i++) {
				Names.push(stationName[i].NAME);
			}
			
			//取几类对应的值。
			var one =0;
			var two =0;
			var three =0;
			var four =0;
			var five =0;
			var six =0;
			var stationData = [];
			var typeData =[];
			if(charData) {
				for(var i=0;i<charData.length;i++) {
					var typeS = charData[i].QUALITY;
					var staName = charData[i].STANAME;
					if(typeS=="好"){
						one=one+1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeOne={};
							TypeOne.value=1;
							TypeOne.name=staName;
							TypeOne.type=typeS;
							TypeOne.number=1;
							stationData.push(TypeOne);
						}
					} else if (typeS=="较好"){
						two += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeTwo={};
							TypeTwo.value=1;
							TypeTwo.name=staName;
							TypeTwo.type=typeS;
							TypeTwo.number=2;
							stationData.push(TypeTwo);
						}
					} else if (typeS=="轻度污染"){
						three += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeThree={};
							TypeThree.value=1;
							TypeThree.name=staName;
							TypeThree.type=typeS;
							TypeThree.number=3;
							stationData.push(TypeThree);
						}
					 } else if (typeS=="中度污染"){
						four += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeFour={};
							TypeFour.value=1;
							TypeFour.name=staName;
							TypeFour.type=typeS;
							TypeFour.number=4;
							stationData.push(TypeFour);
						}
					 } else if (typeS=="重污染"){
						five += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeFive={};
							TypeFive.value=1;
							TypeFive.name=staName;
							TypeFive.type=typeS;
							TypeFive.number=5;
							stationData.push(TypeFive);
						}
					 } else if (typeS=="严重污染"){
						six += 1;
						var isAdd = true;
							for(var k =0;k<stationData.length;k++) {
								if(staName==stationData[k].name && typeS==stationData[k].type) {
									stationData[k].value=stationData[k].value+1;
									isAdd = false;
								}
							}
						if(isAdd) {
							var TypeSix={};
							TypeSix.value=1;
							TypeSix.name=staName;
							TypeSix.type=typeS;
							TypeSix.number=6;
							stationData.push(TypeSix);
						}
					 }
				}
				var colors=[];
				if(one>0) {
					var data={};
					data.value=one;
					data.name="好";
					typeData.push(data);
					colors.push("blue");
				}
				if(two>0) {
					var data={};
					data.value=two;
					data.name="较好";
					typeData.push(data);
					colors.push("blue");
				}
				if(three>0) {
					var data={};
					data.value=three;
					data.name="轻度污染";
					typeData.push(data);
					colors.push("green");
				}
				if(four>0) {
					var data={};
					data.value=four;
					data.name="中度污染";
					typeData.push(data);
					colors.push("yellow");
				}
				if(five>0) {
					var data={};
					data.value=five;
					data.name="重污染";
					typeData.push(data);
					colors.push("orange");
				}
				if(six>0) {
					var data={};
					data.value=six;
					data.name="严重污染";
					typeData.push(data);
					colors.push("red");
				}
				stationData.sort(me.compare("number"));
				//去掉type属性
				var result=[];
				for(var i = 0;i<stationData.length;i++) {
					var array={};
					for(var a in stationData[i])
				    {  
				        if(a!="type"&&a!="number")
				        {
				        	array[a]=stationData[i][a];
				         }
				    }
					result[i]=array;
				}
				stationData = result;
				var titls="综合污染指数";
				if(stationData.length==0) {
					titls="";
				}
				//数据显示格式添加单位
				var format = '';
				if(Units=='（天）') {
					format = '{b} \n {c} （天） ({d}%)';
				} else if(Units=='（周）') {
					format = '{b} \n {c} （周） ({d}%)';
				}else if(Units=='（月）') {
					format = '{b} \n {c} （月） ({d}%)';
				}else if(Units=='（季度）') {
					format = '{b} \n {c} （季度） ({d}%)';
				}else if(Units=='（年）') {
					format = '{b} \n {c} （年） ({d}%)';
				}
				 option = {
 						tooltip : {
							trigger: 'item',
							formatter: "{a} <br/>{b} : {c} ({d}%)"
						},
					    title : {
					        text: titls,						        
					        x:'center',
					        textStyle: {
					            fontSize: 12,
					            fontWeight: 'bolder',
					            color: '#333'          // 主标题文字颜色
					        }
					    },
			            color:colors,
						legend: { 
					        orient : 'horizontal',
					        x : 'left',
					        y:'20px', 
							data:Names
						}, 
					    series : [
									{
									    name:'水质状况',
									    type:'pie',
									     selectedMode: 'single', //单一选中模式 
										 radius: [0, '30%'], //饼图的半径 [内半径，外半径] 
											itemStyle : {
												normal : {
													label : {
														position : 'inner',
													    textStyle:{
														    color:'rgba(0,0,0,0.8)'
														},
													},
													labelLine : {
														show : false
													}
												}
										},
									    data:typeData
									},
							        {
										name:'水质状况', 
										type:'pie', 
										radius: ['40%', '50%'], 
										data:stationData,
											itemStyle:{ 
												normal:{ 
													  label:{ 
														show: true, 
														formatter: format,
													    textStyle:{
														    color:'rgba(0,0,0,0.8)'
														}
													  }, 
													  labelLine :{show:true} 
													} 
										}
									}
					    ]
					};
					                    
				 myChart.setOption(option);
			} else {
				 myChart.setOption("");
			}
		}
		/**
		 * 绘制综合污染指数水质状况变化饼图
		 * 
		 */
		me.DrawBingTuCompPollIndexChangeChart = function(typedata,domid) {
			var charData =[];
			var dateData =[];
			var Units = typedata.labelName;
			charData = typedata.comparePart;
			dateData = typedata.dateTexts;
			var stationName = typedata.stations;
			var chartContainer = document.getElementById(domid);
			var myChart = echarts.init(chartContainer);
			
			var Name=[];
			for(var i = 0;i<stationName.length;i++) {
				Name.push(stationName[i].NAME);
			}
			//取几类对应的值。
			var one =0;
			var two =0;
			var three =0;
			var four =0;
			var five =0;
			var six =0;
			var seven=0;
			var stationData = [];
			var typeData =[];
			if(charData) {
				for(var i=0;i<charData.length;i++) {
					 for (var m =0;m<dateData.length;m++) {
							var typeS = charData[i].QUALITY;
							var staName = charData[i].STANAME;
							var param='';
							param = 'P'+dateData[m]+'POLL_INDEX_CHANGE';

							var typeS = charData[i][param];
							if(typeS=="污染程度稳定"){
								one=one+1;
								var isAdd = true;
									for(var k =0;k<stationData.length;k++) {
										if(staName==stationData[k].name && typeS==stationData[k].type) {
											stationData[k].value=stationData[k].value+1;
											isAdd = false;
										}
									}
								if(isAdd) {
									var TypeOne={};
									TypeOne.value=1;
									TypeOne.name=staName;
									TypeOne.type=typeS;
									TypeOne.number=1;
									stationData.push(TypeOne);
								}
							} else if (typeS=="污染程度有所加重"){
								two += 1;
								var isAdd = true;
									for(var k =0;k<stationData.length;k++) {
										if(staName==stationData[k].name && typeS==stationData[k].type) {
											stationData[k].value=stationData[k].value+1;
											isAdd = false;
										}
									}
								if(isAdd) {
									var TypeTwo={};
									TypeTwo.value=1;
									TypeTwo.name=staName;
									TypeTwo.type=typeS;
									TypeTwo.number=2;
									stationData.push(TypeTwo);
								}
							} else if (typeS=="污染程度有所减轻"){
								three += 1;
								var isAdd = true;
									for(var k =0;k<stationData.length;k++) {
										if(staName==stationData[k].name && typeS==stationData[k].type) {
											stationData[k].value=stationData[k].value+1;
											isAdd = false;
										}
									}
								if(isAdd) {
									var TypeThree={};
									TypeThree.value=1;
									TypeThree.name=staName;
									TypeThree.type=typeS;
									TypeThree.number=3;
									stationData.push(TypeThree);
								}
							 } else if (typeS=="污染程度明显加重"){
								four += 1;
								var isAdd = true;
									for(var k =0;k<stationData.length;k++) {
										if(staName==stationData[k].name && typeS==stationData[k].type) {
											stationData[k].value=stationData[k].value+1;
											isAdd = false;
										}
									}
								if(isAdd) {
									var TypeFour={};
									TypeFour.value=1;
									TypeFour.name=staName;
									TypeFour.type=typeS;
									TypeFour.number=4;
									stationData.push(TypeFour);
								}
							 } else if (typeS=="污染程度明显减轻"){
								five += 1;
								var isAdd = true;
									for(var k =0;k<stationData.length;k++) {
										if(staName==stationData[k].name && typeS==stationData[k].type) {
											stationData[k].value=stationData[k].value+1;
											isAdd = false;
										}
									}
								if(isAdd) {
									var TypeFive={};
									TypeFive.value=1;
									TypeFive.name=staName;
									TypeFive.type=typeS;
									TypeFive.number=5;
									stationData.push(TypeFive);
								}
							 } else if (typeS=="污染程度显著加重"){
								six += 1;
								var isAdd = true;
									for(var k =0;k<stationData.length;k++) {
										if(staName==stationData[k].name && typeS==stationData[k].type) {
											stationData[k].value=stationData[k].value+1;
											isAdd = false;
										}
									}
								if(isAdd) {
									var TypeSix={};
									TypeSix.value=1;
									TypeSix.name=staName;
									TypeSix.type=typeS;
									TypeSix.number=6;
									stationData.push(TypeSix);
								}
							 } else if  (typeS=="污染程度显著减轻") {
								 seven+=1;
									var isAdd = true;
										for(var k =0;k<stationData.length;k++) {
											if(staName==stationData[k].name && typeS==stationData[k].type) {
												stationData[k].value=stationData[k].value+1;
												isAdd = false;
											}
										}
									if(isAdd) {
										var TypeSeven={};
										TypeSeven.value=1;
										TypeSeven.name=staName;
										TypeSeven.type=typeS;
										TypeSeven.number=7;
										stationData.push(TypeSeven);
									}
							 }
					 }
				}
				if(one>0) {
					var data={};
					data.value=one;
					data.name="稳定";
					typeData.push(data);
				}
				if(two>0) {
					var data={};
					data.value=two;
					data.name="有所加重";
					typeData.push(data);
				}
				if(three>0) {
					var data={};
					data.value=three;
					data.name="有所减轻";
					typeData.push(data);
				}
				if(four>0) {
					var data={};
					data.value=four;
					data.name="明显加重";
					typeData.push(data);
				}
				if(five>0) {
					var data={};
					data.value=five;
					data.name="明显减轻";
					typeData.push(data);
				}
				if(six>0) {
					var data={};
					data.value=six;
					data.name="显著加重";
					typeData.push(data);
				} 
				if(seven>0) {
					var data={};
					data.value=seven;
					data.name="显著减轻";
					typeData.push(data);
				} 
				stationData.sort(me.compare("number"));
				//去掉type属性
				var result=[];
				for(var i = 0;i<stationData.length;i++) {
					var array={};
					for(var a in stationData[i])
				    {  
				        if(a!="type"&&a!="number")
				        {
				        	array[a]=stationData[i][a];
				         }
				    }
					result[i]=array;
				}
				stationData = result;
				var titles="综合污染指数变化结果";
				if(stationData.length==0) {
					titles='';
				}
				//数据显示格式添加单位
				var format = '';
				if(Units=='（天）') {
					format = '{b} \n {c} （天） ({d}%)';
				} else if(Units=='（周）') {
					format = '{b} \n {c} （周） ({d}%)';
				}else if(Units=='（月）') {
					format = '{b} \n {c} （月） ({d}%)';
				}else if(Units=='（季度）') {
					format = '{b} \n {c} （季度） ({d}%)';
				}else if(Units=='（年）') {
					format = '{b} \n {c} （年） ({d}%)';
				}
				 var option = {
						    tooltip : {
						        trigger: 'item',
						        formatter: "{a} <br/>{b} : {c} ({d}%)"
						    },
						    title : {
						        text: titles,
						        x:'center',
						        textStyle: {
						            fontSize: 12,
						            fontWeight: 'bolder',
						            color: '#333'          // 主标题文字颜色
						        }
						    },
						    legend: {
						        orient : 'horizontal',
						        x : 'left',
						        y:'20px',
						        data:Name
						    },
					    calculable : true,
					    series : [
									{
									    name:'水质状况',
								        textStyle: {
								            fontSize: 6,
								            fontWeight: 'bolder',
								            color: '#333'          // 主标题文字颜色
								        },
									    type:'pie',
									     selectedMode: 'single', //单一选中模式 
										radius: [0, '30%'], //饼图的半径 [内半径，外半径] 
											itemStyle : {
											normal : {
												label : {
													position : 'inner',
												    textStyle:{
													    color:'rgba(0,0,0,0.8)'
													},
												},
												labelLine : {
													show : false
												}
											}
										},
									    data:typeData
									},
							        {
										name:'水质状况变化', 
								        textStyle: {
								            fontSize: 6,
								            fontWeight: 'bolder',
								            color: '#333'          // 主标题文字颜色
								        },
										type:'pie', 
										radius: ['40%', '50%'], 
							 
										data:stationData,
											itemStyle:{ 
										normal:{ 
											  label:{ 
												show: true, 
												formatter: format,
											    textStyle:{
												    color:'rgba(0,0,0,0.8)'
												}
											  }, 
											  labelLine :{show:true} 
											} 
										}
									}
					    ]
					};
				 myChart.setOption(option);
			} else {
				 myChart.setOption("");
			}
		}
		me.DrawWaterTypeBarChart = function(data,domid) {
			var charData =[];
			charData = data.waterType;
			var chartContainer = document.getElementById(domid);
			var myChart = echarts.init(chartContainer);
			var waterXX = ['I类','II类','III类','IV类','V类','劣V类'];
			if(charData){
				var resultType =[];
				var one=0;
				var two =0;
				var three =0;
				var four =0;
				var five =0;
				var six =0;
				
				for(var i=0;i<charData.length;i++) {
					var typeS = charData[i].WATER_TYPE;
					if(typeS=="I"){
						one=charData[i].NUM;
					} else if (typeS=="II"){
						two=charData[i].NUM;
					} else if (typeS=="III"){
						three=charData[i].NUM;					 
					} else if (typeS=="IV"){
						four=charData[i].NUM;
					} else if (typeS=="V"){
						five=charData[i].NUM;
					 } else if (typeS=="劣V"){
						six=charData[i].NUM;
					 }
				}			
				resultType.push(one);
				resultType.push(two);
				resultType.push(three);
				resultType.push(four);
				resultType.push(five);
				resultType.push(six);
					var option={
						    title : {
						        text: '水质类别分析柱状图'
						    },
						    tooltip : {
						        trigger: 'axis'
						    },
						    toolbox: {
						        show : true,
						        feature : {
						            mark : {show: true},
						            dataView : {show: true, readOnly: false},
						            magicType : {show: true, type: ['line','bar']},
						            restore : {show: true},
						            saveAsImage : {show: true}
						        }
						    },
						    calculable : true,
						    xAxis : [
						        {
						            type : 'category',
						            boundaryGap : [0,0.5],
						            data : waterXX
						        }
						    ],
						    yAxis : [
						        {
						            type : 'value'
						        }
						    ],
						    series : [
						        {
						            name:'水样数量',
						            type:'bar',
						            smooth:true,
						            itemStyle: {
						            	normal: {
						            		   	areaStyle: {type: 'default'},
						            		   	color: function (value){
						            		   	return "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6); }
						            		   	}},
						            data:resultType
						        }
						    ]
						};
					myChart.setOption(option);
			}else {
				myChart.setOption("");
			}
		}		
		me.showSingleMulitChar = function(reportData,domid,parmsToChar,charType){
			var parmMap = {};
			var parmToCheckList = parmsToChar;
			for(var i in parmToCheckList){
				var obj = parmToCheckList[i];
				parmMap[obj.name] = obj.avgText;
			}
			
			var data = reportData[0].report;
			var datetimes = reportData[0].yearHeadText;
			//获取全部历史数据用于图表展示
			
			if(data && data.length){
				
				var parms = [];
				var charDatas = [];
				
				for(var rowIndex=0; rowIndex < data.length;rowIndex++) {
					
					parms.push(data[rowIndex].PARMNAME);
					var charData = [];
					
					for(var i=0;i<datetimes.length;i++) {
						var datetime = datetimes[i];
						var value = data[rowIndex]["P"+datetime];
						if(!value) {
							value = undefined;
						}
						
						if(value){
							var max = data[rowIndex].ABNORMAL_MAX;
							var min = data[rowIndex].ABNORMAL_MIN;
							if(max && min){
								value = value / (max - min);
								value = Math.round(value*1000)/1000
							}
						}
						charData.push(value);
					}
					charDatas.push(charData);
				}
				
				$waterDataCommon.showMulitLineChar(parms,datetimes,charDatas,domid);
			}
		}
		me.showX2XChar = function(reportData,domid,parmsToChar){
			me.showChar(reportData,domid,parmsToChar,"bar");
		}
		me.showTrendChar = function(reportData,domid,parmsToChar,needPre){
			
			if(needPre){
				me.showSingleMulitChar(reportData,domid,parmsToChar,"line");
			}
			else{
				me.showChar(reportData,domid,parmsToChar,"line",needPre);
			}
		}
		/**
		 * 根据数组中的某一属性进行排序
		 */
		me.compare = function(propertyName) { 
			return function (object1, object2) { 
				var value1 = object1[propertyName]; 
				var value2 = object2[propertyName]; 
				if (value2 > value1) { 
				return -1; 
				} 
				else if (value2 < value1) { 
				return 1; 
				} 
				else { 
				return 0; 
				} 
			   } 
			} 
		/**
		 * 绘制河段水质类别饼图
		 * 
		 */
		me.DrawRiverSectionWaterTypeChart = function(typedata,domid) {
			var sectionData =[];
			var Units = typedata.labelName;
			var timeLength = typedata.timeLength;
			sectionData = typedata.sections;
			var chartContainer = document.getElementById(domid);
			var myChart = echarts.init(chartContainer);
			
			var sectionName=[];
			for(var i = 0;i<sectionData.length;i++) {
				sectionName.push(sectionData[i].RIVER_NAME+sectionData[i].SECTION);
			}
			//取几类对应的值。
			var one =0;
			var two =0;
			var three =0;
			var four =0;
			var five =0;
			var six =0;
			var Section = [];
			var typeData =[];
			if(sectionData) {
				for(var i=0;i<sectionData.length;i++) {
					var typeS = sectionData[i].SECTIONTYPE;
					var sectionWaterType = sectionData[i].RIVER_NAME+sectionData[i].SECTION;
					if(typeS=="I"){
							one=one+1;
							var TypeOne={};
							TypeOne.value=timeLength;
							TypeOne.name=sectionWaterType;
							TypeOne.number = 1;
							Section.push(TypeOne);
					} else if (typeS=="II"){
						two += 1;
						var TypeTwo={};
						TypeTwo.value=timeLength;
						TypeTwo.name=sectionWaterType;
						TypeTwo.number = 2;
						Section.push(TypeTwo);

					} else if (typeS=="III"){
							three += 1;					
							var TypeThree={};
							TypeThree.value=timeLength;
							TypeThree.name=sectionWaterType;
							TypeThree.number=3;
							Section.push(TypeThree);
					 } else if (typeS=="IV"){
						 	four += 1;
							var TypeFour={};
							TypeFour.value=timeLength;
							TypeFour.name=sectionWaterType;
							TypeFour.number=4;
							Section.push(TypeFour);
					 } else if (typeS=="V"){
						    five += 1;
							var TypeFive={};
							TypeFive.value=timeLength;
							TypeFive.name=sectionWaterType;
							TypeFive.number=5;
							Section.push(TypeFive);
					 } else if (typeS=="劣V"){
						 	six += 1;
							var TypeSix={};
							TypeSix.value=timeLength;
							TypeSix.name=sectionWaterType;
							TypeSix.number=6;
							Section.push(TypeSix);
					 }
				}
				var colors=[];
				if(one>0) {
					var data={};
					data.value=one;
					data.name="I类";
					typeData.push(data);
					colors.push("blue");
				}
				if(two>0) {
					var data={};
					data.value=two;
					data.name="II类";
					typeData.push(data);
					colors.push("blue");
				}
				if(three>0) {
					var data={};
					data.value=three;
					data.name="III类";
					typeData.push(data);
					colors.push("green");
				}
				if(four>0) {
					var data={};
					data.value=four;
					data.name="IV类";
					typeData.push(data);
					colors.push("yellow");
				}
				if(five>0) {
					var data={};
					data.value=five;
					data.name="V类";
					typeData.push(data);
					colors.push("orange");
				}
				if(six>0) {
					var data={};
					data.value=six;
					data.name="劣V类";
					typeData.push(data);
					colors.push("red");
				}
				Section.sort(me.compare("number"));
				//去掉type属性
				var result=[];
				for(var i = 0;i<Section.length;i++) {
					var array={};
					for(var a in Section[i])
				    {  
				        if(a!="number")
				        {
				        	array[a]=Section[i][a];
				         }
				    }
					result[i]=array;
				}
				Section = result;
				var titles='河段水质类别';
				if(Section.length==0) {
					titles='';
				}
				//数据显示格式添加单位
				var format = '';
				if(Units=='（天）') {
					format = '{b} \n {c} （天） ({d}%)';
				} else if(Units=='（周）') {
					format = '{b} \n {c} （周） ({d}%)';
				}else if(Units=='（月）') {
					format = '{b} \n {c} （月） ({d}%)';
				}else if(Units=='（季度）') {
					format = '{b} \n {c} （季度） ({d}%)';
				}else if(Units=='（年）') {
					format = '{b} \n {c} （年） ({d}%)';
				}
				 var option = {
						    title : {//图形名称
						        text: titles,
						        x:'center',
						        textStyle: {
						            fontSize: 12,
						            fontWeight: 'bolder',
						            color: '#333'          // 主标题文字颜色
						        }
						    },
						       tooltip: { 
								trigger: 'item', 
								formatter: "{a} <br/>{b}: {c} ({d}%)" 
							}, 
							color:colors,
							legend: { 
						        orient : 'horizontal',
						        x : 'center',
						        y:'40px', 
								data:sectionName
							}, 
					    series : [
							        {
							            name:'河段水质类别',
							            textStyle: {
								            fontSize: 6,
								            fontWeight: 'bolder',
								            color: '#333'          // 主标题文字颜色
								        },
							            type:'pie',
							            selectedMode: 'single', //单一选中模式 
										radius: [0, '30%'],
							            x: '20%',
							            width: '40%',
							            funnelAlign: 'right',
							            max: 1548,//饼图的半径 [内半径，外半径] 
											itemStyle : {
											normal : {
												label : {
													position : 'inner',
												    textStyle:{
													    color:'rgba(0,0,0,0.8)'
													}
												},
												labelLine : {
													show : false
												}
											}
										},
							            data:typeData
							        },
							        {
										name:'水质类别', 
										textStyle: {
								            fontSize: 6,
								            fontWeight: 'bolder',
								            color: '#333'          // 主标题文字颜色
								        },
										type:'pie', 
										radius: ['40%', '50%'], 
										data:Section,
										itemStyle:{ 
										normal:{ 
											  label:{ 
												show: true, 
												formatter: format,
											    textStyle:{
												    color:'rgba(0,0,0,0.8)'
												}
											  }, 
											  labelLine :{show:true} 
											} 
									}
									}
					        ]
					};
				 myChart.setOption(option);
			} else {
				 myChart.setOption("");
			}
		}
		
		/**
		 * 绘制河段水质状况饼图
		 * 
		 */
		me.DrawRiverSectionCompPollIndexChart = function(typedata,domid) {
			var sectionData =[];
			var Units = typedata.labelName;
			var timeLength = typedata.timeLength;
			sectionData = typedata.sections;
			var chartContainer = document.getElementById(domid);
			var myChart = echarts.init(chartContainer);
			
			var sectionName=[];
			for(var i = 0;i<sectionData.length;i++) {
				sectionName.push(sectionData[i].RIVER_NAME+sectionData[i].SECTION);
			}
			//取几类对应的值。
			var one =0;
			var two =0;
			var three =0;
			var four =0;
			var five =0;
			var six =0;
			var Section = [];
			var typeData =[];
			if(sectionData) {
				for(var i=0;i<sectionData.length;i++) {
					var typeS = sectionData[i].SECTIONPOLLINDEX;
					var sectionWaterType = sectionData[i].RIVER_NAME+sectionData[i].SECTION;
					if(typeS=="好"){
							one=one+1;
							var TypeOne={};
							TypeOne.value=timeLength;
							TypeOne.name=sectionWaterType;
							TypeOne.number = 1;
							Section.push(TypeOne);
					} else if (typeS=="较好"){
						two += 1;
						var TypeTwo={};
						TypeTwo.value=timeLength;
						TypeTwo.name=sectionWaterType;
						TypeTwo.number = 2;
						Section.push(TypeTwo);

					} else if (typeS=="轻度污染"){
							three += 1;					
							var TypeThree={};
							TypeThree.value=timeLength;
							TypeThree.name=sectionWaterType;
							TypeThree.number=3;
							Section.push(TypeThree);
					 } else if (typeS=="中度污染"){
						 	four += 1;
							var TypeFour={};
							TypeFour.value=timeLength;
							TypeFour.name=sectionWaterType;
							TypeFour.number=4;
							Section.push(TypeFour);
					 } else if (typeS=="重污染"){
						    five += 1;
							var TypeFive={};
							TypeFive.value=timeLength;
							TypeFive.name=sectionWaterType;
							TypeFive.number=5;
							Section.push(TypeFive);
					 } else if (typeS=="严重污染"){
						 	six += 1;
							var TypeSix={};
							TypeSix.value=timeLength;
							TypeSix.name=sectionWaterType;
							TypeSix.number=6;
							Section.push(TypeSix);
					 }
				}
				var colors=[];
				if(one>0) {
					var data={};
					data.value=one;
					data.name="好";
					typeData.push(data);
					colors.push("blue");
				}
				if(two>0) {
					var data={};
					data.value=two;
					data.name="较好";
					typeData.push(data);
					colors.push("blue");
				}
				if(three>0) {
					var data={};
					data.value=three;
					data.name="轻度污染";
					typeData.push(data);
					colors.push("green");
				}
				if(four>0) {
					var data={};
					data.value=four;
					data.name="中度污染";
					typeData.push(data);
					colors.push("yellow");
				}
				if(five>0) {
					var data={};
					data.value=five;
					data.name="重污染";
					typeData.push(data);
					colors.push("orange");
				}
				if(six>0) {
					var data={};
					data.value=six;
					data.name="严重污染";
					typeData.push(data);
					colors.push("red");
				}
				Section.sort(me.compare("number"));
				//去掉type属性
				var result=[];
				for(var i = 0;i<Section.length;i++) {
					var array={};
					for(var a in Section[i])
				    {  
				        if(a!="number")
				        {
				        	array[a]=Section[i][a];
				         }
				    }
					result[i]=array;
				}
				Section = result;
				var titles='河段水质状况';
				if(Section.length==0) {
					titles='';
				}
				//数据显示格式添加单位
				var format = '';
				if(Units=='（天）') {
					format = '{b} \n {c} （天） ({d}%)';
				} else if(Units=='（周）') {
					format = '{b} \n {c} （周） ({d}%)';
				}else if(Units=='（月）') {
					format = '{b} \n {c} （月） ({d}%)';
				}else if(Units=='（季度）') {
					format = '{b} \n {c} （季度） ({d}%)';
				}else if(Units=='（年）') {
					format = '{b} \n {c} （年） ({d}%)';
				}
				 var option = {
						    title : {//图形名称
						        text: titles,
						        x:'center',
						        textStyle: {
						            fontSize: 12,
						            fontWeight: 'bolder',
						            color: '#333'          // 主标题文字颜色
						        }
						    },
						    color:colors,
					        tooltip: { 
								trigger: 'item', 
								formatter: "{a} <br/>{b}: {c} ({d}%)" 
							}, 
							legend: { 
						        orient : 'horizontal',
						        x : 'center',
						        y:'40px', 
								data:sectionName
							}, 
					    series : [
							        {
							            name:'河段水质状况',
							            type:'pie',
							             selectedMode: 'single', //单一选中模式 
										radius: [0, '30%'], //饼图的半径 [内半径，外半径] 
											itemStyle : {
											normal : {
												label : {
													position : 'inner',
												    textStyle:{
													    color:'rgba(0,0,0,0.8)'
													},
												},
												labelLine : {
													show : false
												}
											}
										},
							            data:typeData
							        },
							        {
										name:'河段水质状况', 
										type:'pie', 
										radius: ['40%', '50%'], 
										data:Section,
										itemStyle:{ 
										normal:{ 
											  label:{ 
												show: true, 
												formatter: format,
											    textStyle:{
												    color:'rgba(0,0,0,0.8)'
												}
											  }, 
											  labelLine :{show:true} 
											} 
									}
									}
					        ]
					};
				 myChart.setOption(option);
			} else {
				 myChart.setOption("");
			}
		}
	});
	
}(window, angular));


	                    